using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Scene;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
using System.Windows.Threading;
namespace MicroMsg.Plugin.Shake.Scene
{
	public class ShakeService
	{
		private const string TAG = "ShakeService";
		private const int MAX_COUNT = 100;
		private const int DELETE_COUNT = 15;
		public NetSceneShakeReport mSceneShakeReport;
		public NetSceneShakeGet mSceneShakeGet;
		private static DispatcherTimer mTimer = new DispatcherTimer();
		public bool doShake(double latitude, double longitude)
		{
			this.mSceneShakeReport = new NetSceneShakeReport();
			this.mSceneShakeReport.doScene(latitude, longitude);
			return true;
		}
		public void cancelLastShake()
		{
			if (this.mSceneShakeReport != null)
			{
				this.mSceneShakeReport.cancel();
			}
			if (this.mSceneShakeGet != null)
			{
				this.mSceneShakeGet.cancel();
			}
		}
		public void doSayHi(string username, string content)
		{
			NetSceneSayHiEx netSceneSayHiEx = new NetSceneSayHiEx();
			netSceneSayHiEx.doSceneEx(username, content, AddContactScene.MM_ADDSCENE_SHAKE_SCENE2, EventConst.ON_NETSCENE_SHAKE_SAYHI_SUCCESS, EventConst.ON_NETSCENE_SHAKE_SAYHI_ERR);
		}
		public void saveShakePeopleList(List<ShakePeople> shakeDatList)
		{
			StorageMgr.shackContact.updateList(shakeDatList);
		}
		public void clearShakePeopleList()
		{
			int num = StorageMgr.shackContact.count();
			if (num > 100)
			{
				Log.smethod_5("ShakeService", "clearShakePeopleList");
				StorageMgr.shackContact.deleteTop(num - 100 + 15);
			}
		}
		public void clearAllContact()
		{
			StorageMgr.shackContact.clearAll();
		}
		private static int ShakePeopleComparison(ShakePeople shakePeople_0, ShakePeople shakePeople_1)
		{
			double num = shakePeople_0.dblTimeStamp - shakePeople_1.dblTimeStamp;
			if (Math.Abs(num) < 1.0)
			{
				return 0;
			}
			if (num <= 0.0)
			{
				return 1;
			}
			return -1;
		}
		public List<ShakePeople> getList()
		{
			List<ShakePeople> list = StorageMgr.shackContact.getList();
			if (list != null && list.get_Count() > 1)
			{
				list.Sort(new Comparison<ShakePeople>(ShakeService.ShakePeopleComparison));
				return list;
			}
			return list;
		}
		public static void delayToExec(int seconds, Action action_0)
		{
			ShakeService.mTimer.add_Tick(delegate(object sender, EventArgs e)
			{
				ShakeService.mTimer.Stop();
				action_0.Invoke();
			});
			ShakeService.mTimer.set_Interval(TimeSpan.FromSeconds((double)seconds));
			ShakeService.mTimer.Start();
		}
		public static void test()
		{
		}
	}
}
